package com.example.demo.service.Impl;

import com.example.demo.ao.DistinctAo;
import com.example.demo.mapper.DistinctMapper;
import com.example.demo.service.DistinctService;
import com.example.demo.vo.DistinctVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class DistinctServiceImpl implements DistinctService {


    @Autowired
    private DistinctMapper distinctMapper;

    @Override
    public List<DistinctVo> getDistinctInfo(DistinctAo distinctAo) {
        List<DistinctVo> distinctInfo = distinctMapper.getDistinctInfo(distinctAo);
        List<DistinctVo> objects = new ArrayList<>();

        for (DistinctVo distinctVo : distinctInfo) {
            boolean isDuplicate = false;
            for (DistinctVo vo : objects) {
                if (distinctVo.getCustNo().equals(vo.getCustNo()) && distinctVo.getPlanNo().equals(vo.getPlanNo())) {
                    isDuplicate = true;
                    break;
                }
            }
            if (!isDuplicate) {
                objects.add(distinctVo);
            }
        }

        return objects;
    }




    @Override
    public List<DistinctVo> distinctInfo(DistinctAo distinctAo) {
        List<DistinctVo> distinctInfo = distinctMapper.getDistinctInfo(distinctAo);
        List<DistinctVo> result = new ArrayList<>();

        for (int i = 0; i < distinctInfo.size(); i++) {
            boolean isDuplicate = false;
            for (int j = 0; j < result.size(); j++) {
                if (distinctInfo.get(i).getCustNo().equals(result.get(j).getCustNo()) &&
                        distinctInfo.get(i).getPlanNo().equals(result.get(j).getPlanNo())) {
                    isDuplicate = true;
                    break;
                }
            }
            if (!isDuplicate) {
                result.add(distinctInfo.get(i));
            }
        }

        return result;
    }


}